import { createStore } from 'vuex'

export default createStore({
  state: {
    baseUrl: 'https://fkht.yiquhz.com',
    // baseUrl: 'http://localhost:8087',
    tokens: localStorage.getItem('token') || '',
    userInfos: JSON.parse(localStorage.getItem('userInfo')) || null,
  },
  getters: {
    getToken: state => state.tokens,
    getUserInfo: state => state.userInfos,
  },
  mutations: {
    setToken(state, token) {
      state.tokens = token
      localStorage.setItem('token', token)
    },
    setUserInfo(state, userInfo) {
      state.userInfos = userInfo
      localStorage.setItem('userInfo', JSON.stringify(userInfo))
    },
  },
  actions: {
    login({commit}, token) {
      commit('setToken', token)
    },
    updateUserInfo({commit}, userInfo) {
      commit('setUserInfo', userInfo)
    },
  },
  modules: {}
})
